package com.lincoln.jenkins.test.replys;

import lombok.Data;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/// <param name="opcode">传3即可</param>
/// <param name="user_wxid">收到的FromUsername</param>
/// <param name="user_v1_name">收到的EncryptUsername</param>
/// <param name="user_ticket">收到的Ticket</param>
/// <param name="user_anti_ticket">空着即可</param>
/// <param name="send_content">空着即可</param>
@Data
public class VerifyUser implements Reply{
    int opcode;
    String userWxid;
    String userV1Name;
    String userTicket;
    String userAntiTicket;
    String sendContent;

    @Override
    public String genUrl() {
        try {
            return URLEncoder.encode("&opcode=" + opcode + "&user_wxid=" + userWxid + "&user_v1_name=" + userV1Name + "&user_ticket=" + userTicket + "&user_anti_ticket=" + userAntiTicket +"&send_content=" + sendContent, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            return "";
        }
    }

    /**
     * 同意
     * @param fromUsername
     * @param encryptUsername
     * @param userTicket
     * @return
     */
    public static VerifyUser agree(String fromUsername, String encryptUsername,String userTicket) {
        VerifyUser verifyUser = new VerifyUser();
        verifyUser.setOpcode(3);
        verifyUser.setUserWxid(fromUsername);
        verifyUser.setUserV1Name(encryptUsername);
        verifyUser.setUserTicket(userTicket);
        return verifyUser;
    }
}
